cmake_minimum_required(VERSION 3.0) 
PROJECT(spdlog_API)

#Check os
IF( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
    SET(MACOSX TRUE)
ENDIF()
IF( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
    SET(LINUX TRUE)
ENDIF()

IF (MACOSX)
    SET(BOOST_ROOT /usr/local/include/Cellar/boost)
    SET(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
    # set(CMAKE_CXX_COMPILER "/usr/bin/g++")
    #MESSAGE("set MACOSX_DEPLOYMENT_TARGET to '${MACOSX_DEPLOYMENT_TARGET}'.")
ENDIF(MACOSX)

#Set the C++ options
set(CMAKE_CXX_STANDARD 14)
set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

SET( TARGET_BUILD_FLAGS
  -Wall
  -pthread
  $<$<CONFIG:Release>:-O3>
  $<$<NOT:$<CONFIG:Release>>:-O0>
  $<$<NOT:$<CONFIG:Release>>:-ggdb>
)

find_package(Eigen3 REQUIRED)

#Set the flag for checking testing case
SET(spdlog_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../spdlog")
SET(TEST_FLAG 0)
IF(EXISTS "${spdlog_DIR}" AND IS_DIRECTORY "${spdlog_DIR}" )
  SET(TEST_FLAG 1)
  MESSAGE("${CMAKE_CURRENT_SOURCE_DIR}/../spdlog is exist")
ENDIF()

# SET MODULE_OUT_PATH: Be aware of CMAKE_CURRENT_BINARY_DIR
IF( NOT DEFINED MODULE_OUT_PATH )
  SET( MODULE_OUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib/ )
ENDIF()
SET( LIBRARY_OUTPUT_PATH ${MODULE_OUT_PATH} )

IF(TEST_FLAG)
  ADD_SUBDIRECTORY(${spdlog_DIR} spdlog.out)
  ELSEIF()
    ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/lib/spdlog)
ENDIF(TEST_FLAG)

# Generate static library
SET( SOURCE_FILE 
    log_stream.cpp
)
ADD_LIBRARY(${PROJECT_NAME} STATIC ${SOURCE_FILE})
target_include_directories( ${PROJECT_NAME} 
  PUBLIC
    ${PROJECT_SOURCE_DIR}
    ${EIGEN3_INCLUDE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}/../spdlog/include
)
target_link_libraries( ${PROJECT_NAME}
    spdlog
)

